<template>
  <vxe-grid ref="gridRef4" v-bind="gridOptions4">
    <template #active="{ row }">
      <vxe-button
        mode="text"
        status="primary"
        content="编辑"
        icon="vxe-icon-edit"
        @click.stop="updateRow(row)"
      ></vxe-button>
      <vxe-button
        mode="text"
        status="primary"
        content="删除"
        icon="vxe-icon-edit"
        @click="deleteData(row)"
      ></vxe-button>
      <vxe-button
        mode="text"
        status="primary"
        content="修改状态"
        icon="vxe-icon-edit"
        @click="updateWoRawStatus(row)"
      ></vxe-button>
    </template>
  </vxe-grid>
</template>
<script>
import { VxeUI } from "vxe-pc-ui";
import XEUtils, { first } from "xe-utils";
import {
  getWoTagValueByPage,
  addWoTagValue,
  delWoTagValue,
  updateWoTagValue,
} from "@/api/product/woTagValue";
export default {
  name: "woTagValue",
  props: {},
  data() {
    const gridOptions4 = {
      sortConfig: {
        remote: true,
      },
      loading: false,
      stripe: true,
      showOverflow: true,
      showFooter: true,

      columnConfig: {
        resizable: true,
        drag: true,
      },
      columnDragConfig: {
        trigger: "cell",
        showIcon: false,
        showGuidesStatus: true,
      },
      rowConfig: {
        isHover: true,
      },
      resizableConfig: {
        isDblclickAutoWidth: true,
      },
      pagerConfig: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
      // toolbarConfig: {
      //   refresh: true,
      //   import: true,
      //   export: true,
      //   print: true,
      //   zoom: true,
      //   custom: true,
      //   buttons: [
      //     { name: "新增", code: "myAdd", status: "primary" },
      //     { name: "删除", code: "myDel", status: "error" },
      //     { name: "保存", code: "mySave", status: "success" },
      //   ],
      // },
      formConfig: {
        data: {
          name: "",
          role: "",
          sex: "",
          num: "",
          address: "",
        },
        items: [
          {
            field: "name",
            title: "名称",
            span: 8,

            itemRender: { name: "VxeInput", props: { clearable: true } },
          },

          {
            field: "createTime",
            title: "时间",
            span: 8,

            itemRender: {
              name: "VxeDatePicker",
              props: {
                multiple: true,
              },
            },
          },

          {
            collapseNode: true,
            align: "right",
            span: 8,
            itemRender: {
              name: "VxeButtonGroup",
              options: [
                { type: "submit", content: "搜索", status: "primary" },
                { type: "reset", content: "重置" },
              ],
            },
          },
        ],
      },
      columns: [
        { type: "checkbox", width: 60 },
        { field: "seq", type: "seq", width: 70 },

        {
          field: "deviceCode",
          title: "设备编码",
          sortable: true,
          width: 180,
        },
        {
          field: "tagCode",
          title: "变量编号",
          sortable: true,
          width: 180,
        },
        {
          field: "tagValue",
          title: "变量值",
          sortable: true,
          width: 180,
        },

        {
          field: "wo",
          title: "生产订单",
          sortable: true,
          width: 180,
        },

        {
          field: "productMaterialCode",
          title: "成品物料",
          sortable: true,
          width: 180,
        },
        {
          field: "batchNo",
          title: "批次编号",
          sortable: true,
          width: 180,
        },
        {
          field: "batchCode",
          title: "外部批次编号",
          sortable: true,
          width: 180,
        },
        {
          field: "startMeter",
          title: "开始米数",
          sortable: true,
          width: 180,
        },
        {
          field: "endMeter",
          title: "结束米数",
          sortable: true,
          width: 180,
        },
        // {
        //   field: "startTime",
        //   title: "计划开工时间",
        //   sortable: true,
        //   width: 180,
        // },
        { field: "createTime", title: "创建时间", width: 180 },
        {
          field: "active",
          title: "操作",
          fixed: "right",
          width: 300,
          slots: { default: "active" },
        },
      ],
      scrollX: {
        gt: 0,
        enabled: true,
      },
      scrollY: {
        gt: 0,
        enabled: true,
      },
      proxyConfig: {
        // props: {
        //   result: 'result', // 配置响应结果列表字段
        //   total: 'page.total' // 配置响应结果总页数字段
        // },

        sort: true,
        form: true,
        ajax: {
          query: async ({ page, sorts, form }) => {
            // console.log(page, sorts, form, "----");

            // 默认接收 Promise<{ result: [], page: { total: 100 } }>
            let result = await getWoTagValueByPage({
              ...page,
              // wo: this.woRawSub.wo
              //   ? this.woRawSub.wo
              //   : value
              //   ? JSON.parse(value)
              //   : null,
              /**
               * 子卷信息
               */
              woRawSubId: this.woRawSub.id ? this.woRawSub.id : null,
            });
            this.woRawSub = { id: null, wo: null };
            return {
              result: result.data.records,
              page: {
                total: result.data.total,
              },
            };
          },
        },
      },
    };
    return {
      gridOptions4,
    };
  },
  methods: {},
};
</script>
